package com.zqh.generator;

import cn.hutool.core.io.FileUtil;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;

public class ScriptGenerator {

    public static void doGenerate(String outputPath, String jarPath){

        StringBuilder sb = new StringBuilder();
        sb.append("#!/bin/bash").append("\n");
        sb.append(String.format("java -jar %s   \"$@\"",jarPath)).append("\n");
        FileUtil.writeBytes(sb.toString().getBytes(StandardCharsets.UTF_8),outputPath);

        //     添加可执行权限
        try {
            Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rwxrwxrwx");
            Files.setPosixFilePermissions(Paths.get(outputPath), permissions);
        } catch (Exception e) {

        }

    }

    public static void main(String[] args) {
//        String outputPath = System.getProperty("user.dir") + "/" + "generator";
//        System.out.println(outputPath);
//        doGenerate(outputPath,"./");
//        String shellOutputFilepath = outputPath + "/" + "generator";
//        String jarName = String.format("",meta.getName(),meta.getVersion());
//        String jarPath = "target/" + jarName;
//        ScriptGenerator.doGenerate(shellOutputFilepath,jarPath);

    }

}


